package com.dk.controller;

import com.dk.pojo.Role;
import com.dk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("toRole")
    public String toRole(){
        return "role/show";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public List<Role> getInfo(){
        List<Role> list = roleService.getInfo();
        return list;
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "role/add";
    }
    @RequestMapping("increase")
    @ResponseBody
    public Boolean insertInfo(Role role, @RequestParam("nodesIds")Integer[] nodesIds){
        return roleService.insertInfo(role,nodesIds);
    }
    @RequestMapping("deleteById")
    @ResponseBody
    public boolean deleteById(Integer rid){
        return roleService.deleteById(rid);
    }
    @RequestMapping("toUpdate/{id}")
    public String toUpdate(Model model,@PathVariable("id")Integer id){
        Role role = roleService.selectById(id);
        model.addAttribute("role",role);
        return "role/update";
    }
    @RequestMapping("increaseInfo")
    @ResponseBody
    public Boolean insertInfo2(Role role, @RequestParam("nodesIds[]")Integer[] nodesIds){
        return roleService.insertInfo2(role,nodesIds);
    }
}
